
/**
 * Created by Administrator on 2018/12/30.
 */
package com.game.fg.service;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.java_websocket.drafts.Draft_6455;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;

import java.util.concurrent.ExecutorService;


public class FGMain {
    private static Logger logger = LogManager.getLogger(FGMain.class.getName());
    static ExecutorService executorForMysql = null;
    static boolean started = false;

    public static void main(String[] args) throws Exception {

        ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/spring-config.xml");

        //加载配置文件
        FGConfig.getInstance().loadConfig();
        logger.debug("游戏配置表加载成功");
        //初始化数据库连接池
       /* try {
            DBPool.getDateSource().getConnection().close();
            logger.debug("数据库连接池初始化成功");
        } catch (SQLException e) {
            e.printStackTrace();
        }*/
        //连接redis
        //FGRedis.getInstance().start();
        //初始化线程池
        //executorForMysql = Executors.newFixedThreadPool(1);
        //加载游戏数据
        FGGame.loadGameData();
        //连接认证服务器
        AuthServer.getInstance().start(FGConfig.getInstance().getAuthServerUrl());
        //连接MQ服务器
        MQServer.getInstance().start(FGConfig.getInstance().getMQServerUrl());
        //启动定时器
        FGTimer.getInstance().start();
        //启动socket监听
        int wsPort = FGConfig.getInstance().serverConfig.getWsPort();
        FGWebSocket ws = new FGWebSocket(wsPort, new Draft_6455());
        ws.setConnectionLostTimeout(0);
        ws.start();
        started = true;
    }
}
